perm filename CVTIT.SAI[P,JRA]2 blob sn#302538 filedate 1977-08-30 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00004 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	BEGIN "cvtit"
C00007 00003	proc ESCAPE1	begin	integer e
C00012 00004					! Here 'tis
C00015 ENDMK
C⊗;
BEGIN "cvtit"
COMMENT:	XGPTYP by Ralph Gorin    
		Revised by Hanan Samet	June 12,1975
		Revised by Les Earnest  Dec. 26, 1975
;
DEFINE CRLF="('15&'12)", !="comment", proc="simple procedure";

INTEGER CHCNT,CYPOS;		! input character count, current Y position;
INTEGER CHARSLEFT;		! remaining characters on output line;
INTEGER ARRAY VTIME[1:200];	! vector end Y values;
INTEGER VCOUNT;			! # of active vectors;
boolean filout;			! TRUE if output to file;

integer proc GETCHR;	BEGIN	! get next character;
	integer svword;
	IF CHCNT>1 THEN chcnt←chcnt-1 else  BEGIN SVWORD←WORDIN(1); CHCNT←5; END;
	return((SVWORD←SVWORD ROT 7) land '177)
	END "GETCHR";

define get2="(getchr LSH 7 + getchr)",
	endline="print(crlf); charsleft←69";	! crlf;

proc newline;	if charsleft<69 then begin endline end;
proc outline(string ss);	begin newline; print(ss); endline end;

proc outx(string str); begin 	! output a string;
	if CHARSLEFT < length(str) then begin endline; print("  ");  end;
	print(str);	CHARSLEFT←CHARSLEFT - length(str);
	END; 

string proc oops(string mess);	begin	! error detected;
	if filout then outstr(mess&crlf);	return(mess)
	end;

string proc getint;	begin	! get next byte as signed integer;
	integer gi;
	return(cvs(if (gi←getchr)land '100 then gi lor '777777777600 else gi))
	end;

string proc get4096;	begin	! get next two bytes and check if < 4096;
	integer gi;
	return(if abs(gi←get2)<4096 then cvs(gi) else
	    oops("<ILLEGAL VALUE>")&cvs(gi));
	end;

string proc gety;	begin	! get Y value;
	integer y;
	return(if (y←get2)≥cypos then cvs(cypos←y) else
	    oops("<ILLEGAL SORT>")&cvs(y))
	END;

proc ESCAPE1;	begin	integer e;
	IF (e←getchr)≤'17 THEN outx("<FONT="&cvs(e)&">")
	    else if '40≤e≤'52 then case e-'40 of begin
		! '40; outx("<COLUMN="&get4096&">");
		! '41; outx("<UNDERSCORE "&getint&"  LENGTH "&get4096&">");
		! '42; begin outx("<LINESPACE "&cvs(getchr)&">"); endline end;
		! '43; outx("<BASELINE ADJ. "&getint&">");
		! '44; outx("<PRINT PAGE NUMBER>");
		! '45; BEGIN	integer k;
			newline;
			print("<",e←getchr," BYTES OF HEADING TEXT FOLLOWS:");
			for k←e STEP -1 UNTIL 1 DO print(if (e←getchr)=0 ∨
			    '11≤e≤'15 ∨ e='177 then "<"&e&">" else e);
			print("<END OF HEADING>");	endline;
			END;
		! '46; outx("<START UNDERBAR>");
		! '47; outx("<END UNDERBAR SL="&getint&">");
		! '50; outx("<INTERCHAR. SPACE="&getchr&">");
		! '51; outx("<END UNDERBAR, THICK="&CVS(getchr)&", SL = "&
		    getint&">");
		! '52; outx("<REL. BASELINE ADJ. "&getint&">")
		END
	    else outx("<UNKNOWN ESCAPE SEQUENCE: '177 '001 '"&CVOS(e)&">");
	end "ESCAPE1";

proc VECTOR;		BEGIN	integer v;
	newline;
	print("<VECTOR: Y0=",gety);
	for v←1 step 1 until vcount do if vtime[v]<CYPOS THEN BEGIN "kill vector"
		VTIME[v]←VTIME[VCOUNT];	VCOUNT←VCOUNT-1;
		END;
	print("  X0=",get2);
	if (v←get2 lsh 7+GETCHR) land '4000000 then v←v lor '777770000000;
	print("  DX=",cvf(v/'1000),"  N=",v←get2);
	if VCOUNT<200 then vtime[vcount←vcount+1]←v+cypos-1;	! add vector;
	print(" W=",get2,"> ",VCOUNT," ACTIVE");	endline;
	END "VECTOR";

boolean procedure defile(integer chan; string file,ext,pj,pn);	begin	! file defaults;
	integer nam,ex,ppn;	string sppn;
	boolean flag;
	nam←cvfil(file,ex,ppn);	sppn←cvxstr(ppn);
	sppn←"["&(if ppn lsh -18 then sppn[1 to 3] else pj)&","&
	    (if ppn land '777777 then sppn[4 to 6] else pn)&"]";
	lookup(chan,(file←cvxstr(nam)&".")&cvxstr(ex)&sppn,flag);
	if flag ∧ ex=0 then lookup(chan,file&ext&sppn,flag);
	return(flag)	! TRUE if file not found;
	end;

				! Here 'tis;
integer eof,i;

define toarr=1;	setbreak(toarr,"←",null,"ins");
setformat(0,3);

outstr("[<output> ← ] <input> or ?
");
open(1,"DSK",'10,2,0,200,0,EOF);
while true do begin
	boolean flag;
	string s,dest;

	outstr("*");
	if (s←inchwl)="?" then begin
		outstr("Makes XGP file into readable text file.
To type output, just give <source file> (EXT defaults to ""XGP"").
To save output, say ""<output file> ← <source file>"" (same default).
");		continue
		end;
	dest←scan(s,toarr,i);
	if length(s)=0 then s←dest else setprint(dest,"F");
	dest←cvxstr(call(0,"dskppn"));
	if defile(1,s,"XGP",dest[1 to 3],dest[4 to 6]) then
	    outstr("FILE NOT FOUND: "&S&CRLF) else done;
	END;

vcount←CYPOS←CHCNT←0;	endline;
while ¬eof do if (I←GETCHR)='40 then outx("<SP>")
    else if '11≤I≤'15 then case i-'11 of begin "control"
	outx("<TB>");
	begin print("<LF>"); endline; end;
	outx("<VT>");
	begin outline('14&"<FF>"); CYPOS←vcount←0; end;
	outx("<CR>")
	end "control"
    else if I='177 then begin "delete"
	if 1≤(i←getchr)≤4 then case i-1 of begin
		escape1;
		outx("<COL INC "&getint&">");
		begin newline; print("<SET Y0 ",gety,">"); endline	end;
		vector
		end
	else if i=0 ∨ '11≤i≤'15 ∨ i='177 then OUTX("<'"&CVOS(I)&">")
	else outline("<UNKNOWN ESCAPE SEQUENCE: '177 & '"&CVOS(I)&">");
	end "delete"
    else if I='175 THEN outx("<ALT>")
    else if I≠0 then begin
	print(if I="<" then "<LB>" else if I=">" then "<RB>"else I);	charsleft←charsleft-1;
	end
END "cvtit"